<template>
  <div class="operate-area">
    <div class="operate-inside">
      <div class="doctor-info">
        <template v-if="patientInfo.state">
          您好,{{patientInfo?.result?.name}}
        </template>
      </div>
      <div class="inside">
        <span class="item time">{{ CTDTime / 1000 }}s</span>
        <span class="item back" @click="handleBack" v-if="backShown">返回</span>
        <span class="item home" @click="handleHome">主页</span>
        <span class="item exit" @click="handleExit" v-if="false">退卡</span>
      </div>
    </div>
  </div>
</template>

<script>
let timer = null
export default {
  name: 'PatientNumberOperate',

  componentName: "PatientNumberOperate",

  components: {},

  props: {},

  data() {
    return {
      CTDTime: 0
    }
  },

  computed: {
    // 获取倒计时的初始值
    CTDTimeInfo() {
      return this.$store.getters['DRCbiz/getCTDTimeInfo']
    },

    //获取卡片信息
    cardTypeInfo() {
      return this.$store.getters['DRCbiz/getCardTypeInfo']
    },

    // 患者信息
    patientInfo(){
      return this.$store.getters['DRCbiz/getPatientInfo']
    },

    // 是否隐藏返回按钮
    backShown() {
      let bizInfo = this.$store.getters['DRCbiz/getBizInfo'];
      let stepInfo = this.$store.getters['DRCbiz/getStepsInfo'];
      let OPTypeInfo = this.$store.getters['DRCbiz/getOPTypeInfo'];
      switch (bizInfo?.id) {
        case 3:
          return !(stepInfo === 5)
        case 2:
          if(parseInt(OPTypeInfo.id)===1){
            return !(stepInfo === 7)
          }else {
            return !(stepInfo === 8)
          }
        case 1:
          return !(stepInfo === 11)
      }
    },
  },

  mounted() {
    const self = this;
    self.CTDTime = (self.CTDTimeInfo);
    clearInterval(timer);
    timer = setInterval(() => {
      self.CTDTime = (self.CTDTime - 1000);
      // console.log(`到计时进行中:${self.CTDTime / 1000}`)
      // 到达时间--返回首页-清空定时器
      if ((self.CTDTime) <= 0) {
        self.handleHome();
      }
    }, 1000)
  },

  methods: {
    // 返回上一步
    handleBack() {
      clearInterval(timer);
      this.$emit('handleBack')
    },

    // 返回首页
    handleHome() {
      clearInterval(timer);
      let cardTypeInfo = (this.cardTypeInfo);
      Reflect.set(cardTypeInfo, 'cardNo', null);
      this.$store.dispatch('DRCbiz/setCardTypeInfo', cardTypeInfo);
      this.$store.dispatch('DRCbiz/setPatientInfo', Object());
      this.$store.dispatch('DRCbiz/setDrScheduleList', Object());
      this.$store.dispatch('DRCbiz/setStepsInfo', 1);
      this.$store.dispatch('DRCbiz/setAutoPreAppointReg', false);
      this.$store.dispatch('layout/cancelLoading');
      this.$router.push({
        path: `/DRCbizList`
      });
    },

    // 退卡
    handleExit() {
    },
  },
}

</script>

<style scoped lang="scss">
@import "assets/style";
</style>